<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //字符串转对象
        var str = 'id=1&name=zhangsan&age=18&className=2003';
        var arr = str.split('&');
        var obj = {};
        for(var i = 0; i < arr.length; i++){
            var newArr = arr[i].split('=');
            obj[newArr[0]] = newArr[1];
        }
        console.log(obj);

        //对象转字符串
        var obj1 = {
            id: 1,
            name: 'zhangsan',
            age: 18,
            className: 2003
        }
        var str1 = '';
        for(var key in obj1){
            str1 += key + '=' + obj1[key] + '&';
        }
        console.log(str.substr(0,str1.length - 1));
        
    </script>
</body>
</html>